package com.yl.project.lvyou.questions.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.yl.framework.aspectj.lang.annotation.Log;
import com.yl.framework.aspectj.lang.enums.BusinessType;
import com.yl.project.lvyou.questions.domain.UnmatchedQuestions;
import com.yl.project.lvyou.questions.service.IUnmatchedQuestionsService;
import com.yl.framework.web.controller.BaseController;
import com.yl.framework.web.domain.AjaxResult;
import com.yl.common.utils.poi.ExcelUtil;
import com.yl.framework.web.page.TableDataInfo;

/**
 * 未匹配问题统计Controller
 * 
 * @author yl
 * @date 2025-03-16
 */
@Controller
@RequestMapping("/lvyou/questions")
public class UnmatchedQuestionsController extends BaseController
{
    private String prefix = "scenemanager/questions";

    @Autowired
    private IUnmatchedQuestionsService unmatchedQuestionsService;

    @RequiresPermissions("scenemanager:questions:view")
    @GetMapping()
    public String questions()
    {
        return prefix + "/questions";
    }

    /**
     * 查询未匹配问题统计列表
     */
    @RequiresPermissions("scenemanager:questions:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(UnmatchedQuestions unmatchedQuestions)
    {
        startPage();
        List<UnmatchedQuestions> list = unmatchedQuestionsService.selectUnmatchedQuestionsList(unmatchedQuestions);
        return getDataTable(list);
    }

    /**
     * 导出未匹配问题统计列表
     */
    @RequiresPermissions("scenemanager:questions:export")
    @Log(title = "未匹配问题统计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(UnmatchedQuestions unmatchedQuestions)
    {
        List<UnmatchedQuestions> list = unmatchedQuestionsService.selectUnmatchedQuestionsList(unmatchedQuestions);
        ExcelUtil<UnmatchedQuestions> util = new ExcelUtil<UnmatchedQuestions>(UnmatchedQuestions.class);
        return util.exportExcel(list, "questions");
    }

    /**
     * 新增未匹配问题统计
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存未匹配问题统计
     */
    @RequiresPermissions("scenemanager:questions:add")
    @Log(title = "未匹配问题统计", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(UnmatchedQuestions unmatchedQuestions)
    {
        return toAjax(unmatchedQuestionsService.insertUnmatchedQuestions(unmatchedQuestions));
    }

    /**
     * 修改未匹配问题统计
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        UnmatchedQuestions unmatchedQuestions = unmatchedQuestionsService.selectUnmatchedQuestionsById(id);
        mmap.put("unmatchedQuestions", unmatchedQuestions);
        return prefix + "/edit";
    }

    /**
     * 修改保存未匹配问题统计
     */
    @RequiresPermissions("scenemanager:questions:edit")
    @Log(title = "未匹配问题统计", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(UnmatchedQuestions unmatchedQuestions)
    {
        return toAjax(unmatchedQuestionsService.updateUnmatchedQuestions(unmatchedQuestions));
    }

    /**
     * 删除未匹配问题统计
     */
    @RequiresPermissions("scenemanager:questions:remove")
    @Log(title = "未匹配问题统计", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(unmatchedQuestionsService.deleteUnmatchedQuestionsByIds(ids));
    }
}
